/* eslint-disable no-irregular-whitespace */
import axios from 'axios'
import { getLocal } from '../common/ts/util'
import { Toast } from 'vant'
// import { configs } from '@typescript-eslint/eslint-plugin'
// axios.defaults.baseURL = 'http://localhost:8080'
// axios.defaults.withCredentials = true
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
axios.defaults.headers.Authorization = getLocal('token') || ''
axios.defaults.headers.post['Content-Type'] = 'application/json'

// 服务器返回信息 => [响应拦截器统一处理] => 客户端
axios.interceptors.response.use(
  response => {
    // console.log(response)
    switch (response.code) {
      case 2003: //请求头中Auth为空
        break;
      case 2004: //"请求头中参数有错误"
        break;
      case 2005: //无效token
        localStorage.removeItem('token')
        window.location.href = "/"
        break;
    }
    return response.data;
  }, error => {//拦截失败
    Toast.fail('服务端异常！')
    return Promise.reject(error)
  }
)

export default axios
